package com.gviiii.pprf.netty;

import com.gviiii.pprf.utils.JsonUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.util.CharsetUtil;

import java.util.List;

public class NettyDecoder extends MessageToMessageDecoder<ByteBuf> {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> list) throws Exception {
        if (byteBuf!=null){
            String decode=byteBuf.toString(CharsetUtil.UTF_8);
            NettyMessage object = (NettyMessage) JsonUtils.readObjectByString(decode, NettyMessage.class);
            list.add(object);
        }
    }
}
